﻿using System;

namespace Lesson9_练习题
{
    #region 练习一
    //为整形拓展一个求平方的方法
    static class Tools
    {
        public static int GetSquare(this int value)
        {
            return value * value;
        }
    }
    #endregion

    #region 练习二
    //写一个玩家类 包含姓名、血量、攻击力、防御力等特征，攻击、移动、受伤等方法
    //为该玩家拓展一个自杀的方法
    class Vector
    {
        public int x;
        public int y;
    }
    class Player
    {
        public string name;
        public int Hp;
        public int Atk;
        public int Def;
        public Vector pos;

        /// <summary>
        /// 攻击方法
        /// </summary>
        /// <param name="p">被攻击的对象</param>
        public void Attack(ref Player p)
        {
            p.Hp = p.Hp - (Atk - p.Def);
            Console.WriteLine("{0}受到{1}点伤害，剩余{2}点血量", p.name, Atk - p.Def, p.Hp);
        }
        /// <summary>
        /// 移动方法
        /// </summary>
        /// <param name="xChange">x方向变化量</param>
        /// <param name="yChange">y方向变化量</param>
        public void Move(int xChange, int yChange)
        {
            pos.x += xChange;
            pos.y += yChange;
        }
        /// <summary>
        /// 回复方法
        /// </summary>
        /// <param name="recoNum">回复量</param>
        public void Recover(int recoNum)
        {
            Hp += recoNum;
        }
    }

    static class Tools2
    {
        public static void KillSelf(this Player p)
        {
            p.Hp = 0;
        }
    }
    #endregion
    class Program
    {
        static void Main(string[] args)
        {
            #region 练习一
            int i = 10;
            Console.WriteLine(i.GetSquare());
            #endregion

            #region 练习二
            Player player1 = new Player();
            Player player2 = new Player();
            player1.Hp = 100;
            player2.Hp = 100;
            player2.Def = 20;
            player1.Atk = 60;
            player1.KillSelf();
            Console.WriteLine(player1.Hp);
            player1.Recover(120);
            Console.WriteLine(player1.Hp);
            player1.Attack(ref player2);
            #endregion
        }
    }
}